<template>
  <div class="rc-cont" v-empty="nopermission" xs-empty-icon="nopermission" xs-empty-text="暂无权限">
    <flexbox class="rc-head" direction="row-reverse"> </flexbox>
    <el-table :data="list" :height="tableHeight" stripe style="width: 100%; border: 1px solid #e6e6e6"
      @row-click="handleRowClick">
      <el-table-column prop="realname" label="真实姓名" min-width="100" align="center" show-overflow-tooltip />
      <el-table-column min-width="200" label="统计" align="center" show-overflow-tooltip>
        <template slot-scope="scope">
          <flexbox v-for="(i, k) in scope.row.count" :key="k" justify="center">
            <div class="count-label">
              {{ i.category || "" }}
            </div>
            <div class="count-value">
              {{ i.count || 0 }}
            </div>
          </flexbox>
        </template>
      </el-table-column>
    </el-table>
    <flexbox justify="flex-end">
      <el-pagination class="p-bar" @size-change="handleSizeChange" @current-change="handleCurrentChange"
        :current-page="currentPage" :page-sizes="pageSizes" :page-size.sync="pageSize"
        layout="slot, total, sizes, prev, pager, next, jumper" :total="total" />
    </flexbox>
  </div>
</template>

<script type="text/javascript">
  import loading from "../mixins/loading";
  import {
    crmContractDeputystat
  } from "@/api/customermanagement/contract";

  export default {
    name: "relative-deputystat", // 待办统计
    computed: {},
    mixins: [loading],
    data() {
      return {
        nopermission: false,
        list: [],
        tableHeight: "400px",
        currentPage: 1,
        pageSize: 15,
        pageSizes: [15, 30, 45, 60],
        total: 0,
      };
    },
    watch: {
      id(val) {
        this.list = [];
        this.getDetail();
      },
    },
    props: {
      /** 模块ID */
      id: [String, Number],
      /** 联系人人下 新建商机 需要联系人里的客户信息  订单下需要客户和商机信息 */
      detail: {
        type: Object,
        default: () => {
          return {};
        },
      },
      /** 没有值就是全部类型 有值就是当个类型 */
      crmType: {
        type: String,
        default: "",
      },
      /** 是公海 默认是客户 */
      isSeas: {
        type: Boolean,
        default: false,
      },
      // 是否可编辑
      canEdit: {
        type: Boolean,
        default: false,
      },
    },
    mounted() {
      this.getDetail();
    },
    methods: {
      getDetail() {
        this.loading = true;
        crmContractDeputystat({
            contract_id: this.id,
            limit: this.pageSize,
            page: this.currentPage,
          })
          .then((res) => {
            this.nopermission = false;
            this.loading = false;
            this.list = res.data.list;
            this.total = res.data.dataCount;
          })
          .catch((data) => {
            if (data.code == 102) {
              this.nopermission = true;
            }
            this.loading = false;
          });
      },
      // 更改每页展示数量
      handleSizeChange(val) {
        this.pageSize = val;
        this.getDetail();
      },
      // 更改当前页数
      handleCurrentChange(val) {
        this.currentPage = val;
        this.getDetail();
      },
    },
  };

</script>
<style lang="scss" scoped>
  @import "../styles/relativecrm.scss";

  .count-label {
    width: 200px;
    min-height: 30px;
    line-height: 30px;
    text-align: center;
    background: #f5f5f5;
    border: 1px solid #e8e8e8;
    overflow: hidden;
  }

  .count-value {
    width: 200px;
    min-height: 30px;
    line-height: 30px;
    text-align: center;
    border: 1px solid #e8e8e8;
  }

</style>
